package logic

import (
	"context"
	"fmt"
	"order/model"
	"order/order"
	"time"

	"order/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderNotifyLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderNotifyLogic {
	return &OrderNotifyLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderNotifyLogic) OrderNotify(in *order.OrderNotifyRequest) (*order.OrderNotifyResponse, error) {
	// todo: add your logic here and delete this line
	fmt.Println("***************")
	fmt.Println(in.OutTradeNo)

	time.Sleep(50 * time.Second)

	err := model.Db.Table("orders").Where("order_num = ?", in.OutTradeNo).Update("order_status", model.OrderStateOver).Error
	if err != nil {
		return nil, err
	}
	//TODO:收到OrderID
	//TODO:修改订单状态
	return &order.OrderNotifyResponse{}, nil
}
